﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI;
using WeifenLuo.WinFormsUI.Docking;
using dbgservlib;

namespace wfdbg
{
    public partial class Form_Output : ToolWindow
    {
        private Timer m_timer = null;
        private IDbgService m_pDbgService;

        public Form_Output(IDbgService pDbgService)
        {
            m_pDbgService = pDbgService;
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form_Output));
            InitializeComponent();
            
            m_timer = new Timer();
            m_timer.Tick += new EventHandler(LoadOutput);
            m_timer.Interval = 100;
            m_timer.Enabled = true;
        }

        protected override string GetPersistString()
        {
            return GetType().ToString();
        }

        private void LoadOutput(object sender, EventArgs e)
        {
            if (IsDisposed)
                return;

            string stOutput = null;
            do
            {
                try
                {
                    m_pDbgService.GetOutput(out stOutput);
                    if (stOutput != null)
                    {
                        rtbOutput.AppendText(stOutput);
                        rtbOutput.SelectionStart = rtbOutput.Text.Length;
                        rtbOutput.ScrollToCaret();
                    }
                }
                catch (Exception/* exc*/)
                {
                    stOutput = null;
                }
            } while (stOutput != null);
        }
    }
}
